#ifndef SERVER_CONTROLLER_H
#define SERVER_CONTROLLER_H

#include <oatpp-websocket/Handshaker.hpp>
#include <oatpp/web/server/api/ApiController.hpp>
#include <oatpp/network/ConnectionHandler.hpp>
#include <oatpp/core/macro/codegen.hpp>
#include <oatpp/core/macro/component.hpp>
#include "ServerHandle.h"

#include OATPP_CODEGEN_BEGIN(ApiController)

class ServerController : public oatpp::web::server::api::ApiController
{
private:
    OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, websocketConnectionHandler, "websocket");
    ServerHandle* _serverHandle;
public:
    ServerController(ServerHandle* serverHandle,OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
        : oatpp::web::server::api::ApiController(objectMapper),_serverHandle(serverHandle)
    {}

    ENDPOINT("GET", "/", root) {

    const char* pageTemplate =
        "<html lang='en'>"
        "<head>"
            "<meta charset=utf-8/>"
        "</head>"
        "<body>"
            "<p>Hello Multithreaded WebSocket Server!</p>"
            "<p>"
            "<code>websocket endpoint is: localhost:7600/ws</code>"
            "</p>"
        "</body>"
        "</html>";

    return createResponse(Status::CODE_200, pageTemplate);

    };

    ENDPOINT("GET", "CameraConnect", CameraConnect, REQUEST(std::shared_ptr<IncomingRequest>, request)) {
        return oatpp::websocket::Handshaker::serversideHandshake(request->getHeaders(), websocketConnectionHandler);
    };
};

#include OATPP_CODEGEN_END(ApiController)

#endif